<?php
//Set up the system
require('config.include.php');
//Auth stuff
require('auth.include.php');
//Save data if given
$saved=false;
//The path to the theme html
$themefile='../'.THEMEFOLDER.'/'.THEME.'/'.THEME.'.html';
if(isset($_POST['templateCode'])) {
	$tmpFile=fopen($themefile,'w+');
	fwrite($tmpFile,fetch::unescapePostVar($_POST['templateCode']));
	fclose($tmpFile);
	$saved=true;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Edit Template</title>
<link rel="stylesheet" href="admin.css" />
</head>

<body>
<div id="wrapper">
	<div id="header">
    	<?php echo('<a href="../" class="breadcrumb">'.SITE_TITLE.'</a> &raquo; <a href="dashboard.php" class="breadcrumb">Dashboard</a> &raquo; <a href="settemplate.php" class="breadcrumb">Edit Template</a>'); ?>
    </div>
    <div id="sidebar">
<?php
	require('nav.include.php');
?>
    </div>
    <div id="content">
        <div class="contentblock">
		<h2>Update Template HTML</h2>
		<form action="settemplate.php" method="post">
			<textarea name="templateCode" class="full" cols="60" rows="30"><?php echo(htmlentities(file_get_contents($themefile),ENT_QUOTES,"UTF-8")); ?></textarea>
			<br />
			<input type="submit" value="Save"/>
		</form>
		<?php
		if($saved)
			echo('Template saved.<br />
				HTML changes will not appear until the template has been <a href="rebuildtemplate.php?rebuild">rebuilt</a>.');
		?>
		</div>
    </div>
    <div id="footer">
    </div>
</div>
</body>
</html>